package mycollections;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class demo2 {
    public static void main(String[] args) {
        Student s1=new Student("zhangsan",17);
        Student s2=new Student("lisi",16);
        Student s3=new Student("wangwu",18);
        ArrayList<Student> list=new ArrayList<Student>();
        list.add(s1);
        list.add(s2);
        list.add(s3);
        Collections.sort(list, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                //以学生的年龄升序
                int age=o1.getAge()-o2.getAge();
                return age;
            }
        });
        for (Student student : list) {
            System.out.println(student);
        }
    }
}
